# 当前路径加入系统变量 ------------------------------------
import os
import sys

root_path = os.getcwd()
# print(root_path)
sys.path.append(root_path)
# -----------------------------------------------------

from fastapi import FastAPI
import uvicorn
from loguru import logger
from typing import Optional
from bean.Item import Item

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World1"}


@app.get("/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"itemId": item_id, 'q': q}


@app.post("/create")
async def add_item(item: Item):
    logger.info(f'收到请求参数{item}')
    return item


if __name__ == "__main__":
    logger.add("./log/log.txt", rotation="00:00")
    uvicorn.run("main:app", host='127.0.0.1', port=8000, reload=False)
